class Solution {
    public int minSubArrayLen(int target, int[] nums) {
        int res = nums.length + 1;
        int slow = 0, sum = 0;
        for (int fast = 0; fast < nums.length; fast++) {
            sum += nums[fast];
            while (sum >= target) {
                res = (fast-slow+1)<res?(fast-slow+1):res;
                sum -= nums[slow++];
            }
        }
        return res>nums.length?0:res;
    }
}